package com.zoke.loveway.ui;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;

import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.zoke.loveway.R;
import com.zoke.loveway.adapter.PointIndicatorAdapter;
import com.zoke.loveway.adapter.WelcomeAdapter;
import com.zoke.loveway.view.indicator.FixedIndicatorView;
import com.zoke.loveway.view.indicator.Indicator.OnItemSelectedListener;

/**
 * 欢迎页
 * 
 * @author Jack
 *
 */
@ContentView(R.layout.activity_welcome)
public class Welcomes extends LoveWayUI implements OnPageChangeListener,
		OnItemSelectedListener {
	@ViewInject(R.id.guide_viewPager)
	private ViewPager mGuideViewpager;
	@ViewInject(R.id.guide_indicator)
	private FixedIndicatorView mIndicator;
	private WelcomeAdapter mAdapter;
	private PointIndicatorAdapter mIndicatorAdapter;

	private List<Integer> mList = new ArrayList<Integer>();

	public static void openWelcomes() {
		Intent intent = new Intent(mContext, Welcomes.class);
		open(intent);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mList.add(R.drawable.welcome_1);
		mList.add(R.drawable.welcome_2);
		mList.add(R.drawable.welcome_3);
		mList.add(R.drawable.welcome_4);
		mAdapter = new WelcomeAdapter(Welcomes.this, mList);
		mIndicatorAdapter = new PointIndicatorAdapter(mList, Welcomes.this);
		mGuideViewpager.setAdapter(mAdapter);
		mIndicator.setAdapter(mIndicatorAdapter);
		initViewpager();
	}

	private void initViewpager() {
		mGuideViewpager.setOnPageChangeListener(this);
		mIndicator.setOnItemSelectListener(this);
	}

	@Override
	public void onPageScrollStateChanged(int arg0) {

	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {

	}

	@Override
	public void onPageSelected(int arg0) {
		mIndicator.setCurrentItem(arg0);
	}

	@Override
	public void onItemSelected(View selectItemView, int select, int preSelect) {
		mGuideViewpager.setCurrentItem(select);
	}

}
